// custom-tab-bar/index.ts
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 1,
    list: [
      {
        icon: 'home-o',
        text: '小马视界',
        name: 'home',
        url: '/pages/home/index'
      },
      {
        icon: 'tv-o',
        text: '短视频',
        name: 'short-video',
        url: '/pages/short-video/index'
      },
      {
        icon: 'hotel-o',
        text: '企业号',
        name: 'enterprise',
        url: '/pages/enterprise/index'
      },
      {
        icon: 'gem-o',
        text: '私密空间',
        name: 'private-space',
        url: '/pages/private-space/index'
      },
      {
        icon: 'user-o',
        text: '我的',
        name: 'user',
        url: '/pages/user/index'
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event: any) {
      this.setData({ active: event.detail });
      wx.switchTab({
        url: this.data.list[event.detail].url
      });
    },
    init() {
      const page: any = getCurrentPages().pop();
      this.setData({
        active: this.data.list.findIndex(item => item.url === `/${page.route}`)
      });
    },
    getHeight(callBack) {
      const query = this.createSelectorQuery()
      query.select(".main-tab-class").boundingClientRect()
      query.exec((res) => callBack(res[0].height))
    }
  }

})
